package us.pigsoft.client;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.util.ArrayList;

public abstract class Mob {
	
	enum AttackTypes
	{
		ORBITAL,
		HOMING,
		ERRATIC,
		ZIGZAG
	}

	double x, y, originX, originY, speed, maxSpeed, angle, health, 
		   maxHealth, coastRate, acceleration, turnSpeed;
	ArrayList<Shape> shapes;
	ArrayList<Color> shapeColors;
	GuiGame game;
	Dimension size;
	
	public abstract void update();
	public abstract void onDeath();
	public abstract void attack();
	
	public Mob(GuiGame game, Dimension bounds)
	{
		this.game = game;
		x = y = angle = 0;
		health = maxHealth = 100.0;
		shapes = new ArrayList<Shape>();
		shapeColors = new ArrayList<Color>();
		size = bounds;
		originX = bounds.getWidth() / 2;
		originY = bounds.getHeight() / 2;
		maxSpeed = 6.0;
		speed = 0.0;
		coastRate = 0.15;
		acceleration = 1.0;
		turnSpeed = 0.1;
	}
	
	public void draw(Graphics2D g)
	{
		// Shapes are drawn in order that they are in the array
		// e.g. index 0 is drawn before index 10
		g.translate(x, y);
		g.rotate(angle);
		for(int i = 0; i < shapes.size(); i++)
		{
			g.setColor(shapeColors.get(i));
			g.draw(shapes.get(i));
		}
		g.rotate(-angle);
		g.translate(-x, -y);
	}
	
	public void facePlayer(Point playerPosition)
	{
		double newAngle = Math.atan2(playerPosition.y - y, playerPosition.x - x);
		
		// Change angle to sin angle
		if(angle < newAngle)
			angle += acceleration;
		else if(angle > newAngle)
			angle -= acceleration;
	}
}
